//package org.activoricordi.app.model
package edu.ucdavis.fiehnlab.alchemy.alchemyAdmin.model

import net.liftweb.mapper._
import _root_.java.math.MathContext
import net.liftweb.util.FieldError
import net.liftweb.http._
import net.liftweb.common.{Box,Full,Empty,Failure,ParamFailure}
import scala.xml._

//import java.math.MathContext

/**
 * Created with IntelliJ IDEA.
 * User: naru
 * Date: 3/27/13
 * Time: 1:56 PM
 * To change this template use File | Settings | File Templates.
 */

/**
 * define method dataModel
 *
 */
class Method extends LongKeyedMapper[Method] with IdPK with OneToMany[Long,Method]{
  def getSingleton = Method

 // def primaryKeyField = id
  //object id extends MappedLongIndex(this)

  object name extends MappedString(this,200)  {

    /**
     *
     * validation for Method Name unique and non empty
     */
    override def validations = valUnique(S.?("The method is already Added.")) _ ::valMinLen(1,S.?("Method name can't be null")) _ ::super.validations


  }

  object riWindow extends MappedDecimal(this, MathContext.DECIMAL64,5)

  object massWindow extends MappedDecimal(this, MathContext.DECIMAL64,5)

  object description extends MappedTextarea(this,2048)


  def allCompound : List[Compound] =
    Compound.findAll(By(Compound.method, this.id))

  /**
   * define one-to-many relation between Method and Compounds
   * */
  def compounds = Compound.findAll(By(Compound.method,this.id))

  //object compounds  extends MappedLongForeignKey(Compound, Compound.method, OrderBy(Compound.id, Ascending))

}


  object Method extends Method with LongKeyedMetaMapper[Method] {
    /**
     * define database table name for dtaModel Method
     */
    override  def dbTableName = "methods"
    override def fieldOrder = List(name,riWindow,massWindow,description)
  }


